home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
E-Z Progress Bar 1.0a
/
ChiselClass.cp
next >
Wrap
Text File
|
1995-03-14
|
7KB
|
381 lines
#include "ChiselClass.h"
void ChiselClass::InitializeVars(short options)
{
useRGB=RGBAvailable();
darkGrey.red=darkGrey.green=darkGrey.blue=0xAAAA;
myDirtyWhite.red=myDirtyWhite.blue=myDirtyWhite.green=0xF000;
myWhite.red=myWhite.green=myWhite.blue=0xFFFF;
myBlack.red=myBlack.green=myBlack.blue=0x0000;
borderWidth=3;
blackWidth=borderWidth/2;
// kColorPress=0x0D00; // Good for thousands of colors
kColorPress=0x0440; // Acceptable for 256 colors
kMaxColor=0XEEEE;
kMinColor=0x0000;
SetOptions(options);
}
void ChiselClass::SetOptions(short options)
{
liteChisel=(options & dirtyWhite) ? myDirtyWhite : myWhite;
addBlackBorder=!(options & noBlackBorder);
chiselWay=!(options & chiselIn);
darkChisel=darkGrey;
}
ChiselClass::ChiselClass(short options)
{
InitializeVars(options);
useDefaultRect=0;
}
ChiselClass::ChiselClass(Rect defaultRect, short options)
{
InitializeVars(options);
useDefaultRect=1;
dRect=defaultRect;
}
void ChiselClass::Chisel(Rect theRect, Boolean out)
{
PenState oldState;
RGBColor oldColor;
GetPenState(&oldState);
GetForeColor(&oldColor);
PenSize(borderWidth, borderWidth);
PenMode(patCopy);
if (addBlackBorder) {
PenSize(blackWidth, blackWidth);
InsetRect(&theRect, -blackWidth, -blackWidth);
ForeColor(blackColor);
FrameRect(&theRect);
if (!out)
MoveTo(theRect.left+blackWidth/2, theRect.top);
else
MoveTo(theRect.right-blackWidth-blackWidth/2, theRect.top);
if ((blackWidth/2)<1)
Move((out) ? -1 : 1, 0);
Line(0, theRect.bottom-theRect.top-blackWidth); // Add thick border on side
MoveTo(theRect.left, theRect.bottom-blackWidth-blackWidth/2);
if ((blackWidth/2)<1)
Move(0, -1);
Line(theRect.right-theRect.left, 0); // Add thick border on bottom
PenSize(borderWidth, borderWidth);
}
InsetRect(&theRect, -borderWidth, -borderWidth);
if (!out) {
if (useRGB)
RGBForeColor(&darkChisel);
else
PenPat(<Gray);
}
else {
if (useRGB)
RGBForeColor(&liteChisel);
else
PenPat(&white);
}
MoveTo(theRect.left, theRect.bottom-borderWidth);
LineTo(theRect.left, theRect.top);
LineTo(theRect.right-borderWidth, theRect.top);
if (!out) {
if (useRGB)
RGBForeColor(&liteChisel);
else
PenPat(&white);
}
else {
if (useRGB)
RGBForeColor(&darkChisel);
else
PenPat(<Gray);
}
MoveTo(theRect.right-borderWidth, theRect.top+borderWidth);
LineTo(theRect.right-borderWidth, theRect.bottom-borderWidth);
LineTo(theRect.left+borderWidth, theRect.bottom-borderWidth);
if (!useRGB) {
InsetRect(&theRect, -1, -1);
PenSize(1, 1);
PenPat(&black);
FrameRect(&theRect);
}
SetPenState(&oldState);
RGBForeColor(&oldColor);
}
void ChiselClass::ChiselIn(Rect theRect)
{
Chisel(theRect, 0);
}
void ChiselClass::ChiselOut(Rect theRect)
{
Chisel(theRect, 1);
}
void ChiselClass::Chisel()
{
if (useDefaultRect)
Chisel(dRect, chiselWay);
}
void ChiselClass::Chisel(Rect theRect)
{
Chisel(theRect, chiselWay);
}
void ChiselClass::HairChisel()
{
if (useDefaultRect)
HairChisel(dRect, chiselWay);
}
void ChiselClass::HairChisel(Rect theRect)
{
HairChisel(theRect, chiselWay);
}
void ChiselClass::HairChiselOut(Rect theRect)
{
HairChisel(theRect, 1);
}
void ChiselClass::HairChiselIn(Rect theRect)
{
HairChisel(theRect, 0);
}
void ChiselClass::HairChisel(Rect &theRect, Boolean out)
{
RGBColor oldColor;
PenState oldState;
short width=theRect.right-theRect.left, height=theRect.bottom-theRect.top;
GetPenState(&oldState);
PenSize(1,1);
PenMode(patCopy);
if (useRGB) {
GetForeColor(&oldColor);
if (out)
RGBForeColor(&liteChisel);
else
RGBForeColor(&darkChisel);
MoveTo(theRect.left, theRect.bottom);
Line(0, -height);
Line(width, 0);
if (out)
RGBForeColor(&darkChisel);
else
RGBForeColor(&liteChisel);
Line(0, height);
Line(-width, 0);
RGBForeColor(&oldColor);
}
else {
ForeColor(whiteColor);
MoveTo(theRect.right, theRect.top);
Line(0, height);
Line(-width, 0);
ForeColor(blackColor);
Line(0, -height);
Line(width, 0);
}
SetPenState(&oldState);
}
Rect ChiselClass::ChiselRect(Rect theRect)
{
InsetRect(&theRect, -borderWidth, -borderWidth);
if (addBlackBorder)
InsetRect(&theRect, -blackWidth, -blackWidth);
if (!useRGB)
InsetRect(&theRect, -borderWidth, -borderWidth);
return theRect;
}
Rect ChiselClass::ChiselRect()
{
if (useDefaultRect)
return ChiselRect(dRect);
return dRect;
}
Rect ChiselClass::PreChisel(Rect theRect)
{
InsetRect(&theRect, borderWidth, borderWidth);
if (addBlackBorder)
InsetRect(&theRect, blackWidth, blackWidth);
if (!useRGB)
InsetRect(&theRect, borderWidth, borderWidth);
return theRect;
}
Rect ChiselClass::PreChisel()
{
if (useDefaultRect)
return PreChisel(dRect);
return dRect;
}
void ChiselClass::CleanRect(Rect theRect)
{
theRect=ChiselRect(theRect);
EraseRect(&theRect);
}
void ChiselClass::CleanRect()
{
if (useDefaultRect)
CleanRect(dRect);
}
void ChiselClass::InvalChisel(Rect theRect)
{
theRect=ChiselRect(theRect);
InvalRect(&theRect);
}
void ChiselClass::InvalChisel()
{
if (useDefaultRect)
InvalChisel(dRect);
}
void ChiselClass::SetDefaultRect(Rect &theRect)
{
dRect=theRect;
useDefaultRect=1;
}
void ChiselClass::SetDarkChiselColor(RGBColor darkColor)
{
darkChisel=darkColor;
}
void ChiselClass::SetLiteChiselColor(RGBColor liteColor)
{
liteChisel=liteColor;
}
void ChiselClass::LiteDarkFrom(RGBColor baseColor)
{
LiteFrom(baseColor);
DarkFrom(baseColor);
}
void ChiselClass::LiteFrom(RGBColor baseColor)
{
int hi=GetHi(baseColor);
int amount=((hi+kColorPress)>kMaxColor) ? kMaxColor-hi : kColorPress;
baseColor.red+=amount;
baseColor.green+=amount;
baseColor.blue+=amount;
SetLiteChiselColor(baseColor);
}
void ChiselClass::DarkFrom(RGBColor baseColor)
{
int lo=GetLo(baseColor);
int amount=((lo-kColorPress)<kMinColor) ? lo-kMinColor : kColorPress;
baseColor.red-=amount;
baseColor.green-=amount;
baseColor.blue-=amount;
SetDarkChiselColor(baseColor);
}
int ChiselClass::GetHi(RGBColor &color)
{
int max=color.red;
max=(color.green>max) ? color.green : max;
max=(color.blue>max) ? color.blue : max;
return max;
}
int ChiselClass::GetLo(RGBColor &color)
{
int min=color.red;
min=(color.green<min) ? color.green : min;
min=(color.blue<min) ? color.blue : min;
return min;
}
void ChiselClass::SetFrameColor(RGBColor frameColor)
{
myBlack=frameColor;
}
void ChiselClass::SetChiselWidth(short width)
{
borderWidth=width;
blackWidth=borderWidth/2;
}
void ChiselClass::SetBlackBorderWidth(short width)
{
blackWidth=width;
}
void ChiselClass::SetChiselWay(short chiselDir)
{
chiselWay=!(chiselIn & chiselDir);
}
void ChiselClass::UseDirtyWhite(Boolean dirty)
{
liteChisel=(dirty) ? myDirtyWhite : myWhite;
}
void ChiselClass::UseBlackFrame(Boolean useBlackBorder)
{
addBlackBorder=useBlackBorder;
}